package com.libgdxbar.pvzlikegame.systems;

import com.badlogic.gdx.utils.Array;
import com.libgdxbar.pvzlikegame.entities.BaseEntity;
import com.libgdxbar.pvzlikegame.entities.EntitySystem;

import org.libgdxbar.projects.interfaces.ILooper;

public class UpdateSystem extends EntitySystem {

	private final Array<ILooper> updateable = new Array<>();

	@Override
	public void onEntityAdded(BaseEntity baseEntity) {
		if (baseEntity instanceof ILooper) {
			ILooper looper = (ILooper) baseEntity;
			updateable.add(looper);
		}
	}

	@Override
	public void onEntityRemoved(BaseEntity baseEntity) {
		if (baseEntity instanceof ILooper) {
			ILooper looper = (ILooper) baseEntity;
			updateable.removeValue(looper, true);
		}
	}

	@Override
	public void run(float delta) {
		for (ILooper looper : updateable) {
			looper.run(delta);
		}
	}

}
